package com.example.papercutting;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.view.View;

public class FoldedPaper extends View {
    public static int x = Data.canvasWidth / 2;//圆心x
    public static int y = Data.canvasHeight / 2 + 200;//圆心y
    public static int r = ((Data.canvasWidth < Data.canvasHeight) ? Data.canvasWidth : Data.canvasHeight) / 2;//半径
    public float startAngle = Data.startAngle;
    public float sweepAngle = Data.sweepAngle;

    private int color;
    Paint paint = new Paint();
    Path path = new Path();

    public FoldedPaper(Context context) {
        super(context);
    }

    // 添加新的构造函数
    public FoldedPaper(Context context, int color) {
        super(context);
        this.color = color;
    }

    @SuppressLint({"ClickableViewAccessibility", "DrawAllocation"})
    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawColor(Data.transparentBackground);
        paint.setAntiAlias(true);

        @SuppressLint("DrawAllocation")
        Rect rect = new Rect(x - r, y - r, x + r, y + r);
        path.addArc(new RectF(rect), startAngle, sweepAngle);//添加扇形路径
        path.lineTo(x, y);
        canvas.clipPath(path);//截取扇形区为可绘制区

        paint.setColor(color);
        canvas.drawArc(new RectF(rect), startAngle, sweepAngle, true, paint);//画出扇形区域
    }
}
